﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WpfPdfReader
{
    public class FileItemModel : IComparer<DateTime>, IEquatable<FileItemModel>
    {
        /// <summary>
        /// 文件名称
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 文件路径
        /// </summary>
        public string FullName { get; set; }
        /// <summary>
        /// 打开时间
        /// </summary>
        public DateTime Time { get; set; }
        /// <summary>
        /// 上一次浏览到的页码
        /// </summary>
        public int Page { get; set; }
        /// <summary>
        /// 最后一次浏览的页面图片路径
        /// </summary>
        public string LastPageBmpPath { get; set; }
        /// <summary>
        /// 封面图片路径
        /// </summary>
        public string TitlePageBmpPath { get; set; }

        private List<BookMark> bookMarks = new List<BookMark>();
        public List<BookMark> BookMarks
        {
            get { return this.bookMarks; }
            set { this.bookMarks = value; }
        }

        public int Compare(DateTime x, DateTime y)
        {
            return DateTime.Compare(x, y);
        }

        public override string ToString()
        {
            string s1 = string.Format(
                "<Book>\n" +
                "<Name>{0}</Name>\n" +
                "<FullName>{1}</FullName>\n" +
                "<Time>{2}</Time>\n" +
                "<Page>{3}</Page>\n" +
                "<LastPageBmpPath>{4}</LastPageBmpPath>\n" +
                "<TitlePageBmpPath>{5}</TitlePageBmpPath>\n"
                , Name, FullName, Time.ToString(), Page, LastPageBmpPath, TitlePageBmpPath);

            string s2 = "<BookMarks>\n";
            foreach (var item in this.BookMarks)
            {
                s2 += item.ToString();
            }
            s2 += "</BookMarks>\n</Book>";

            return s1 + s2;
        }

        public bool Equals(FileItemModel other)
        {
            if (other == null)
                return false;
            bool isEuals = this.FullName == other.FullName;
            return isEuals;
        }
    }
}
